package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.InteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description InteractionQuestionController
 * @Author WJH
 * @Date 2024-12-27
 */

@RestController
@RequestMapping("/questions")
@Api(tags = "问答系统")
public class InteractionQuestionController {
    @Autowired
    private InteractionQuestionService questionService;

    @PostMapping
    @ApiOperation("新增问题")
    public void addQuestion(@RequestBody QuestionFormDTO dto){
        questionService.addQuestion(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改问题")
    public void updateQuestion(@RequestBody QuestionFormDTO dto,@PathVariable Long id){
        questionService.updateQuestion(dto,id);
    }

    /**
     * 用户端分页查询问题
     * @param questionPageQuery
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用户端分页查询问题")
    public PageDTO<QuestionVO> queryPage(QuestionPageQuery questionPageQuery){
        return questionService.queryPage(questionPageQuery);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO getDetailById(@PathVariable Long id){
        return questionService.getDetailById(id);
    }

    /**
     * 删除我的问题
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除我的问题")
    public void deleteQuestionById(@PathVariable Long id){
        questionService.deleteQuestionById(id);
    }
}
